package Mapper;

import entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    //功能:根据用户id查询用户信息
    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User getUserById(int userId);


    //功能:根据用户名字查询用户id.
    @Select("select user_id from user where nickname = #{name}")
    int getUserIdById(String name);


    //根据用户名字查询相关记录
    @Select("SELECT * from user where nickname = #{name}")
    List<User> getUserByName(String name);


    //根据图片查询记录
    @Select("select images from user where images = #{image}")
    public List<User> getUserImages(String image);


    //获得当前最大user_id+1
    @Select("SELECT COALESCE(MAX(user_id), 0) + 1 FROM user")
    public int nextId();


    //插入新用户
    @Insert("INSERT INTO user (user_id, nickname, images) VALUES (#{userid}, #{nickname}, #{images})")
    public int insertUser(User user);
}